package com.lhy.controller;

import com.lhy.domain.DoctorDuty;
import com.lhy.service.DoctorDutyService;
import com.lhy.utils.Pagination;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.print.Doc;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @author 汪
 */
@Controller
public class DoctorDutyController {
    @Autowired
    DoctorDutyService doctorDutyService;
    @RequestMapping("/showDutyToDoctor")
    public String showDutyToDoctor(HttpServletRequest req, HttpServletResponse resp){
        List<DoctorDuty> doctorDuties=doctorDutyService.showAllDuty();
        HttpSession session = req.getSession();
        session.setAttribute("doctorDuties",doctorDuties);
        return "myyszblist";
    }
    @RequestMapping("/addDuty")
    public String addDuty(HttpServletRequest req, HttpServletResponse resp){
        Integer docid = Integer.parseInt(req.getParameter("docid"));
        SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd");
        Date dutyday=null;
        try {
            dutyday = simpleDateFormat.parse(req.getParameter("dutyday"));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        DoctorDuty doctorDuty=new DoctorDuty();
        doctorDuty.setDocid(docid);
        doctorDuty.setDutyday(dutyday);
        doctorDutyService.addDuty(doctorDuty);
        return "main";
    }
    @RequestMapping("/deleteDuty")
    public String deleteDuty(HttpServletRequest req, HttpServletResponse resp){
        Integer ddid = Integer.parseInt(req.getParameter("ddid"));
        doctorDutyService.deleteDuty(ddid);
        return "main";
    }
    @RequestMapping("/findSomeDuty")
    public String findSomeDuty(Pagination<DoctorDuty> page, DoctorDuty doctorDuty,HttpServletRequest req, HttpServletResponse resp){
        System.out.println(doctorDuty);
        page.setQueryObject(doctorDuty);
        doctorDutyService.findSomeDuty(page);
        HttpSession session = req.getSession();
        session.setAttribute("doctorDuties",page);
        return "yszblist";
    }
}
